<!-- 小程序列表 -->
<template>
	<div class="">
		<el-button type="primary" @click="syncTemp()" style="margin-bottom: 20px;">同步模板库</el-button>
		<el-table :data="tableData" style="width: 100%" border>
			<el-table-column prop="id" label="模板ID"></el-table-column>
			<el-table-column prop="version" label="版本号"></el-table-column>
			<el-table-column prop="desc" label="描述"></el-table-column>
			<el-table-column prop="createtime" label="创建时间"></el-table-column>
			<el-table-column label="操作" width="130px">
				<template slot-scope="scope">
					<el-button type="text" @click="delTemplate(scope.row.id)"><span style="color: red;">删除</span></el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="el-pagination">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page="page"
				:page-sizes="[10, 100, 200, 300, 400]"
				:page-size="size"
				layout="total, sizes, prev, pager, next, jumper"
				:total="total"
			></el-pagination>
		</div>
	</div>
</template>

<script>
import Api from '@/api/pages/xcx/index.js';
export default {
	name: 'dmk-1',
	data() {
		return {
			page: 1,
			size: 10,
			total: 0,
			tableData: [],
		};
	},
	mounted() {
		this.getData();
	},
	methods: {
		getData() {
			let data = {
				pageNumber: this.page,
				pageSize: this.size,
				type:2		
			};
			Api.codeQuery(data).then(res => {
				if (res.state) {
					this.tableData = res.data.list;
					this.total = res.data.totalRow;
				} else {
					this.$message(res.msg);
				}
			});
		},
		// 同步微信代码库
		syncTemp() {
			let data = {
				type:2	
			};
			Api.sync_temp(data).then(res => {
				if (res.state) {
					this.$message({
						showClose: true,
						message: res.msg,
						type: 'success'
					});
				} else {
					this.$message(res.msg);
				}
				this.getData();
			});
		},
		// 删除模板
		delTemplate(id) {
			this.$confirm('您确定要删除该模板吗?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					Api.del_template({
						id: id
					}).then(res => {
						if (res.state) {
							this.$message({
								showClose: true,
								message: res.msg,
								type: 'success'
							});
						} else {
							this.$message(res.msg);
						}
						this.getData();
					});
				})
				.catch(() => {});
		},
		// 草稿添加到代码模版
		addToTemplate(id) {
			this.$confirm('您确定添加此草稿到代码模板吗?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					Api.addToTemplate({
						id: id
					}).then(res => {
						if (res.state) {
							this.$message({
								showClose: true,
								message: res.msg,
								type: 'success'
							});
						} else {
							this.$message(res.msg);
						}
						this.getData();
					});
				})
				.catch(() => {});
		},
		handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
			this.size = val;
			this.getData();
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
			this.page = val;
			this.getData();
		}
	}
};
</script>
<style lang="scss" scoped></style>

<style lang="scss">
.dialogVideo {
	.el-dialog__body {
		padding: 20px;
	}
}
</style>
